#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <vector>
#include <string>
#include "HttpUtil.h"

#define MAXSIZE 1024
#pragma comment(lib, "Wininet.lib") 

bool urlopen(_TCHAR* url, std::vector<std::string>& vecStr)
{
    bool bResut = true;

    HINTERNET hSession = InternetOpen(_T("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    if(hSession != NULL)
    {
        HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);

        if (hHttp != NULL)
        {
            //wprintf_s(_T("%s\n"), url);
            BYTE Temp[MAXSIZE];
            ULONG Number = 1;
            while (Number > 0)
            {
                InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);
                Temp[Number] = '\0';
                //printf("%s", Temp);
                vecStr.push_back(std::string((char *)Temp));
            }
            InternetCloseHandle(hHttp);
            hHttp = NULL;
        }
        else
        {
            bResut = false;
        }
        InternetCloseHandle(hSession);
        hSession = NULL;
    }
    else
    {
        bResut = false;
    }

    return bResut;
}